package com.mycompany.test.basic;

import java.io.Serializable;

public class JsonResult<T> implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 3133701337570122647L;
	public static final int SUCCESS = 0;
	public static final int FAIL = 1;
	private int state;
	private T data;
	private String message;
	
	public JsonResult() {
		super();
	}
	public JsonResult(int state, T data, String message) {
		super();
		this.state = state;
		this.data = data;
		this.message = message;
	}
	public JsonResult(T data) {
		super();
		this.state = SUCCESS;
		this.data = data;
		this.message = "success";
	}
	public JsonResult(int state, Throwable e) {
		super();
		this.state = state;
		this.data = null;
		this.message = e.getMessage();
	}
	public JsonResult(Throwable e) {
		super();
		this.state = FAIL;
		this.data = null;
		this.message = e.getMessage();
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	@Override
	public String toString() {
		return "JsonResult [state=" + state + ", data=" + data + ", message=" + message + "]";
	}
	
}
